#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=880;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn][maxn],sum[maxn][maxn];
LL arr[maxn*maxn],tot=0;
LL n,k;
bool check(LL val){
     for(LL i=1;i<=n;i++){
        for(LL j=1;j<=n;j++){
            sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+(a[i][j]>=val);
        }
     }
     for(LL i=k;i<=n;i++){
        for(LL j=k;j<=n;j++){
            LL x2=i;LL y2=j;
            LL x1=i-k+1;LL y1=j-k+1;
            LL res=sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];
            if(res<(k*k/2)+1) return false;
        }
     }
     return true;
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    cin>>n>>k;
    for(LL i=1;i<=n;i++){
        for(LL j=1;j<=n;j++){
            cin>>a[i][j];
            arr[++tot]=a[i][j];
        }
    }
    sort(arr+1,arr+1+tot);
    LL l=1;LL r=tot;
    while(l<r){
        LL mid=(l+r+1)>>1;
        if(check(arr[mid])) l=mid;
        else r=mid-1;
    }
    cout<<arr[l]<<"\n";
   	return 0;
}
